{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n",
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "from keras.layers import Flatten, Conv2D, MaxPooling2D, Dense, Dropout, Input, Activation\n",
    "from keras.models import Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_1 (InputLayer)         (None, 224, 224, 1)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_1 (Conv2D)            (None, 224, 224, 64)      640       \n",
      "_________________________________________________________________\n",
      "max_pooling2d_1 (MaxPooling2 (None, 112, 112, 64)      0         \n",
      "_________________________________________________________________\n",
      "conv2d_2 (Conv2D)            (None, 112, 112, 128)     73856     \n",
      "_________________________________________________________________\n",
      "max_pooling2d_2 (MaxPooling2 (None, 56, 56, 128)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_3 (Conv2D)            (None, 56, 56, 256)       295168    \n",
      "_________________________________________________________________\n",
      "conv2d_4 (Conv2D)            (None, 56, 56, 256)       590080    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_3 (MaxPooling2 (None, 28, 28, 256)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_5 (Conv2D)            (None, 28, 28, 512)       1180160   \n",
      "_________________________________________________________________\n",
      "conv2d_6 (Conv2D)            (None, 28, 28, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "max_pooling2d_4 (MaxPooling2 (None, 14, 14, 512)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_7 (Conv2D)            (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_8 (Conv2D)            (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "max_pooling2d_5 (MaxPooling2 (None, 7, 7, 512)         0         \n",
      "_________________________________________________________________\n",
      "dense_1 (Dense)              (None, 7, 7, 4096)        2101248   \n",
      "_________________________________________________________________\n",
      "dropout_1 (Dropout)          (None, 7, 7, 4096)        0         \n",
      "_________________________________________________________________\n",
      "dense_2 (Dense)              (None, 7, 7, 4096)        16781312  \n",
      "_________________________________________________________________\n",
      "dropout_2 (Dropout)          (None, 7, 7, 4096)        0         \n",
      "_________________________________________________________________\n",
      "dense_3 (Dense)              (None, 7, 7, 10)          40970     \n",
      "_________________________________________________________________\n",
      "activation_1 (Activation)    (None, 7, 7, 10)          0         \n",
      "=================================================================\n",
      "Total params: 28,142,858\n",
      "Trainable params: 28,142,858\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# VGG-A\n",
    "def vgg_a(x):\n",
    "    x1 = Conv2D(64, (3,3), padding = 'same', activation='relu')(x)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(128, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Dense(4096, activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Dense(4096, activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Dense(10)(x1)\n",
    "    output = Activation('softmax')(x1)\n",
    "    return output\n",
    "\n",
    "input_img = Input(shape = (224,224,1))\n",
    "VGG_A = Model(input_img,vgg_a(input_img))\n",
    "VGG_A.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_1 (InputLayer)         (None, 224, 224, 1)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_9 (Conv2D)            (None, 224, 224, 64)      640       \n",
      "_________________________________________________________________\n",
      "conv2d_10 (Conv2D)           (None, 224, 224, 64)      36928     \n",
      "_________________________________________________________________\n",
      "max_pooling2d_6 (MaxPooling2 (None, 112, 112, 64)      0         \n",
      "_________________________________________________________________\n",
      "conv2d_11 (Conv2D)           (None, 112, 112, 128)     73856     \n",
      "_________________________________________________________________\n",
      "conv2d_12 (Conv2D)           (None, 112, 112, 128)     147584    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_7 (MaxPooling2 (None, 56, 56, 128)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_13 (Conv2D)           (None, 56, 56, 256)       295168    \n",
      "_________________________________________________________________\n",
      "conv2d_14 (Conv2D)           (None, 56, 56, 256)       590080    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_8 (MaxPooling2 (None, 28, 28, 256)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_15 (Conv2D)           (None, 28, 28, 512)       1180160   \n",
      "_________________________________________________________________\n",
      "conv2d_16 (Conv2D)           (None, 28, 28, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "max_pooling2d_9 (MaxPooling2 (None, 14, 14, 512)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_17 (Conv2D)           (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_18 (Conv2D)           (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "max_pooling2d_10 (MaxPooling (None, 7, 7, 512)         0         \n",
      "_________________________________________________________________\n",
      "dense_4 (Dense)              (None, 7, 7, 4096)        2101248   \n",
      "_________________________________________________________________\n",
      "dropout_3 (Dropout)          (None, 7, 7, 4096)        0         \n",
      "_________________________________________________________________\n",
      "dense_5 (Dense)              (None, 7, 7, 4096)        16781312  \n",
      "_________________________________________________________________\n",
      "dropout_4 (Dropout)          (None, 7, 7, 4096)        0         \n",
      "_________________________________________________________________\n",
      "dense_6 (Dense)              (None, 7, 7, 10)          40970     \n",
      "_________________________________________________________________\n",
      "activation_2 (Activation)    (None, 7, 7, 10)          0         \n",
      "=================================================================\n",
      "Total params: 28,327,370\n",
      "Trainable params: 28,327,370\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# VGG-B\n",
    "def vgg_b(x):\n",
    "    x1 = Conv2D(64, (3,3), padding = 'same', activation='relu')(x)\n",
    "    x1 = Conv2D(64, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(128, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(128, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Dense(4096, activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Dense(4096, activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Dense(10)(x1)\n",
    "    output = Activation('softmax')(x1)\n",
    "    return output\n",
    "\n",
    "VGG_B = Model(input_img,vgg_b(input_img))\n",
    "VGG_B.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_1 (InputLayer)         (None, 224, 224, 1)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_19 (Conv2D)           (None, 224, 224, 64)      640       \n",
      "_________________________________________________________________\n",
      "conv2d_20 (Conv2D)           (None, 224, 224, 64)      36928     \n",
      "_________________________________________________________________\n",
      "max_pooling2d_11 (MaxPooling (None, 112, 112, 64)      0         \n",
      "_________________________________________________________________\n",
      "conv2d_21 (Conv2D)           (None, 112, 112, 128)     73856     \n",
      "_________________________________________________________________\n",
      "conv2d_22 (Conv2D)           (None, 112, 112, 128)     147584    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_12 (MaxPooling (None, 56, 56, 128)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_23 (Conv2D)           (None, 56, 56, 256)       295168    \n",
      "_________________________________________________________________\n",
      "conv2d_24 (Conv2D)           (None, 56, 56, 256)       590080    \n",
      "_________________________________________________________________\n",
      "conv2d_25 (Conv2D)           (None, 56, 56, 256)       65792     \n",
      "_________________________________________________________________\n",
      "max_pooling2d_13 (MaxPooling (None, 28, 28, 256)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_26 (Conv2D)           (None, 28, 28, 512)       1180160   \n",
      "_________________________________________________________________\n",
      "conv2d_27 (Conv2D)           (None, 28, 28, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_28 (Conv2D)           (None, 28, 28, 512)       262656    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_14 (MaxPooling (None, 14, 14, 512)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_29 (Conv2D)           (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_30 (Conv2D)           (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_31 (Conv2D)           (None, 14, 14, 512)       262656    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_15 (MaxPooling (None, 7, 7, 512)         0         \n",
      "_________________________________________________________________\n",
      "dense_7 (Dense)              (None, 7, 7, 4096)        2101248   \n",
      "_________________________________________________________________\n",
      "dropout_5 (Dropout)          (None, 7, 7, 4096)        0         \n",
      "_________________________________________________________________\n",
      "dense_8 (Dense)              (None, 7, 7, 4096)        16781312  \n",
      "_________________________________________________________________\n",
      "dropout_6 (Dropout)          (None, 7, 7, 4096)        0         \n",
      "_________________________________________________________________\n",
      "dense_9 (Dense)              (None, 7, 7, 10)          40970     \n",
      "_________________________________________________________________\n",
      "activation_3 (Activation)    (None, 7, 7, 10)          0         \n",
      "=================================================================\n",
      "Total params: 28,918,474\n",
      "Trainable params: 28,918,474\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# VGG-C\n",
    "def vgg_c(x):\n",
    "    x1 = Conv2D(64, (3,3), padding = 'same', activation='relu')(x)\n",
    "    x1 = Conv2D(64, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(128, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(128, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (1,1), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (1,1), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (1,1), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Dense(4096, activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Dense(4096, activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Dense(10)(x1)\n",
    "    output = Activation('softmax')(x1)\n",
    "    return output\n",
    "\n",
    "VGG_C = Model(input_img,vgg_c(input_img))\n",
    "VGG_C.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_1 (InputLayer)         (None, 224, 224, 1)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_32 (Conv2D)           (None, 224, 224, 64)      640       \n",
      "_________________________________________________________________\n",
      "conv2d_33 (Conv2D)           (None, 224, 224, 64)      36928     \n",
      "_________________________________________________________________\n",
      "max_pooling2d_16 (MaxPooling (None, 112, 112, 64)      0         \n",
      "_________________________________________________________________\n",
      "conv2d_34 (Conv2D)           (None, 112, 112, 128)     73856     \n",
      "_________________________________________________________________\n",
      "conv2d_35 (Conv2D)           (None, 112, 112, 128)     147584    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_17 (MaxPooling (None, 56, 56, 128)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_36 (Conv2D)           (None, 56, 56, 256)       295168    \n",
      "_________________________________________________________________\n",
      "conv2d_37 (Conv2D)           (None, 56, 56, 256)       590080    \n",
      "_________________________________________________________________\n",
      "conv2d_38 (Conv2D)           (None, 56, 56, 256)       590080    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_18 (MaxPooling (None, 28, 28, 256)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_39 (Conv2D)           (None, 28, 28, 512)       1180160   \n",
      "_________________________________________________________________\n",
      "conv2d_40 (Conv2D)           (None, 28, 28, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_41 (Conv2D)           (None, 28, 28, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "max_pooling2d_19 (MaxPooling (None, 14, 14, 512)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_42 (Conv2D)           (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_43 (Conv2D)           (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_44 (Conv2D)           (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "max_pooling2d_20 (MaxPooling (None, 7, 7, 512)         0         \n",
      "_________________________________________________________________\n",
      "dense_10 (Dense)             (None, 7, 7, 4096)        2101248   \n",
      "_________________________________________________________________\n",
      "dropout_7 (Dropout)          (None, 7, 7, 4096)        0         \n",
      "_________________________________________________________________\n",
      "dense_11 (Dense)             (None, 7, 7, 4096)        16781312  \n",
      "_________________________________________________________________\n",
      "dropout_8 (Dropout)          (None, 7, 7, 4096)        0         \n",
      "_________________________________________________________________\n",
      "dense_12 (Dense)             (None, 7, 7, 10)          40970     \n",
      "_________________________________________________________________\n",
      "activation_4 (Activation)    (None, 7, 7, 10)          0         \n",
      "=================================================================\n",
      "Total params: 33,637,066\n",
      "Trainable params: 33,637,066\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# VGG-D\n",
    "def vgg_d(x):\n",
    "    x1 = Conv2D(64, (3,3), padding = 'same', activation='relu')(x)\n",
    "    x1 = Conv2D(64, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(128, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(128, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Flatten()(x1)\n",
    "    x1 = Dense(4096, activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Dense(4096, activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Dense(10)(x1)\n",
    "    output = Activation('softmax')(x1)\n",
    "    return output\n",
    "\n",
    "VGG_D = Model(input_img,vgg_d(input_img))\n",
    "VGG_D.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_1 (InputLayer)         (None, 224, 224, 1)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_187 (Conv2D)          (None, 224, 224, 64)      640       \n",
      "_________________________________________________________________\n",
      "conv2d_188 (Conv2D)          (None, 224, 224, 64)      36928     \n",
      "_________________________________________________________________\n",
      "max_pooling2d_61 (MaxPooling (None, 112, 112, 64)      0         \n",
      "_________________________________________________________________\n",
      "conv2d_189 (Conv2D)          (None, 112, 112, 128)     73856     \n",
      "_________________________________________________________________\n",
      "conv2d_190 (Conv2D)          (None, 112, 112, 128)     147584    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_62 (MaxPooling (None, 56, 56, 128)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_191 (Conv2D)          (None, 56, 56, 256)       295168    \n",
      "_________________________________________________________________\n",
      "conv2d_192 (Conv2D)          (None, 56, 56, 256)       590080    \n",
      "_________________________________________________________________\n",
      "conv2d_193 (Conv2D)          (None, 56, 56, 256)       590080    \n",
      "_________________________________________________________________\n",
      "conv2d_194 (Conv2D)          (None, 56, 56, 256)       590080    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_63 (MaxPooling (None, 28, 28, 256)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_195 (Conv2D)          (None, 28, 28, 512)       1180160   \n",
      "_________________________________________________________________\n",
      "conv2d_196 (Conv2D)          (None, 28, 28, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_197 (Conv2D)          (None, 28, 28, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_198 (Conv2D)          (None, 28, 28, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "max_pooling2d_64 (MaxPooling (None, 14, 14, 512)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_199 (Conv2D)          (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_200 (Conv2D)          (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_201 (Conv2D)          (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_202 (Conv2D)          (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "max_pooling2d_65 (MaxPooling (None, 7, 7, 512)         0         \n",
      "_________________________________________________________________\n",
      "flatten_3 (Flatten)          (None, 25088)             0         \n",
      "_________________________________________________________________\n",
      "dense_22 (Dense)             (None, 4096)              102764544 \n",
      "_________________________________________________________________\n",
      "dropout_23 (Dropout)         (None, 4096)              0         \n",
      "_________________________________________________________________\n",
      "dense_23 (Dense)             (None, 4096)              16781312  \n",
      "_________________________________________________________________\n",
      "dropout_24 (Dropout)         (None, 4096)              0         \n",
      "_________________________________________________________________\n",
      "dense_24 (Dense)             (None, 10)                40970     \n",
      "_________________________________________________________________\n",
      "activation_12 (Activation)   (None, 10)                0         \n",
      "=================================================================\n",
      "Total params: 139,610,058\n",
      "Trainable params: 139,610,058\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# VGG-E\n",
    "def vgg_e(x):\n",
    "    x1 = Conv2D(64, (3,3), padding = 'same', activation='relu')(x)\n",
    "    x1 = Conv2D(64, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(128, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(128, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Flatten()(x1)\n",
    "    x1 = Dense(4096, activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Dense(4096, activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Dense(10)(x1)\n",
    "    output = Activation('softmax')(x1)\n",
    "    return output\n",
    "\n",
    "VGG_E = Model(input_img,vgg_e(input_img))\n",
    "VGG_E.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_1 (InputLayer)         (None, 224, 224, 1)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_203 (Conv2D)          (None, 224, 224, 64)      640       \n",
      "_________________________________________________________________\n",
      "conv2d_204 (Conv2D)          (None, 224, 224, 64)      36928     \n",
      "_________________________________________________________________\n",
      "max_pooling2d_66 (MaxPooling (None, 112, 112, 64)      0         \n",
      "_________________________________________________________________\n",
      "conv2d_205 (Conv2D)          (None, 112, 112, 128)     73856     \n",
      "_________________________________________________________________\n",
      "conv2d_206 (Conv2D)          (None, 112, 112, 128)     147584    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_67 (MaxPooling (None, 56, 56, 128)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_207 (Conv2D)          (None, 56, 56, 256)       295168    \n",
      "_________________________________________________________________\n",
      "conv2d_208 (Conv2D)          (None, 56, 56, 256)       590080    \n",
      "_________________________________________________________________\n",
      "conv2d_209 (Conv2D)          (None, 56, 56, 256)       590080    \n",
      "_________________________________________________________________\n",
      "conv2d_210 (Conv2D)          (None, 56, 56, 256)       590080    \n",
      "_________________________________________________________________\n",
      "max_pooling2d_68 (MaxPooling (None, 28, 28, 256)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_211 (Conv2D)          (None, 28, 28, 512)       1180160   \n",
      "_________________________________________________________________\n",
      "conv2d_212 (Conv2D)          (None, 28, 28, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_213 (Conv2D)          (None, 28, 28, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_214 (Conv2D)          (None, 28, 28, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "max_pooling2d_69 (MaxPooling (None, 14, 14, 512)       0         \n",
      "_________________________________________________________________\n",
      "conv2d_215 (Conv2D)          (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_216 (Conv2D)          (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_217 (Conv2D)          (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "conv2d_218 (Conv2D)          (None, 14, 14, 512)       2359808   \n",
      "_________________________________________________________________\n",
      "max_pooling2d_70 (MaxPooling (None, 7, 7, 512)         0         \n",
      "_________________________________________________________________\n",
      "conv2d_219 (Conv2D)          (None, 1, 1, 4096)        102764544 \n",
      "_________________________________________________________________\n",
      "dropout_25 (Dropout)         (None, 1, 1, 4096)        0         \n",
      "_________________________________________________________________\n",
      "conv2d_220 (Conv2D)          (None, 1, 1, 4096)        16781312  \n",
      "_________________________________________________________________\n",
      "dropout_26 (Dropout)         (None, 1, 1, 4096)        0         \n",
      "_________________________________________________________________\n",
      "conv2d_221 (Conv2D)          (None, 1, 1, 10)          40970     \n",
      "_________________________________________________________________\n",
      "activation_13 (Activation)   (None, 1, 1, 10)          0         \n",
      "=================================================================\n",
      "Total params: 139,610,058\n",
      "Trainable params: 139,610,058\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# VGG-E-test\n",
    "def vgg_e_test(x):\n",
    "    x1 = Conv2D(64, (3,3), padding = 'same', activation='relu')(x)\n",
    "    x1 = Conv2D(64, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(128, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(128, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(256, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = Conv2D(512, (3,3), padding = 'same', activation='relu')(x1)\n",
    "    x1 = MaxPooling2D(pool_size=(2,2), strides=2)(x1)  \n",
    "    x1 = Conv2D(4096, (7,7), activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Conv2D(4096, (1, 1), activation='relu')(x1)\n",
    "    x1 = Dropout(0.5)(x1)\n",
    "    x1 = Conv2D(10,(1,1))(x1)\n",
    "    output = Activation('softmax')(x1)\n",
    "    return output\n",
    "\n",
    "VGG_E = Model(input_img,vgg_e_test(input_img))\n",
    "VGG_E.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
